@extends('public.dashboard_base')
@section('title', '我的域名')

@section('content')
    <div class="control_panel_content">
        <div class="navBreadcrumb">
            <ul>
                <li>域名管理</li>
                <li><a href="/domain/list">我的域名</a></li>
            </ul>
        </div>
        <div class="panel domain_list_panel">
            <form action="/domain/list" id="queryForm" method="post">
                <div class="sub_nav_container">
                    <input type="hidden" name="type1" id="type1" value="">
                    <ul class="clearfix">
                        <li class="active"><a href="/domain/list" data-type="normal">我的域名</a></li>
                        <li><a href="/domain/list?type=1" data-type="approach_expire">30天内到期</a></li>
                        <li><a href="/domain/list?type=2" data-type="already_expire">已过期</a></li>
                        <li><a href="/domain/list?type=3" data-type="redemption">赎回期</a></li>
                    </ul>
                </div>
                <div class="domain_list_search">
                    <table>
                        <tbody>
                        <tr>
                            <td>关键字：</td>
                            <td>
                                <textarea name="ym" id="ym" placeholder="每行一个域名" class="text_textarea" style="width: 143px;"></textarea>
                            </td>
                            <td>后缀：</td>
                            <td>
                                <div class="suffix_container">
                                    <input type="text" placeholder="所有后缀" readonly="" style="width: 143px;">
                                    <input type="hidden" name="suffix">
                                    <div class="suffix_list">
                                        <ul>
                                        </ul>
                                        <div>
                                            <a href="javascript:;" class="btn btn_primary">确定</a>&ensp;
                                            <a href="javascript:;" class="btn btn_default">取消</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td>注册商：</td>
                            <td>
                                <select name="registrar">
                                    <option value="">请选择</option>
                                </select>
                            </td>
                            <td>分组：</td>
                            <td>
                                <select name="groupId">
                                    <option value="">请选择</option>
                                    <option value="1.1">未分组</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>状态：</td>
                            <td>
                                <select name="status">
                                    <option value="">请选择</option>
                                    <option value="1">正常</option>
                                    <option value="2">已过期</option>
                                    <option value="3">赎回期</option>
                                    <option value="4">等待实名</option>
                                    <option value="5">实名中</option>
                                    <option value="6">实名失败</option>
                                    <!-- <option value="PASS_SEND">已发送转移密码</option>-->
                                    <option value="88">转出中</option>
                                    <!-- <option value="TRADE">正在交易</option>-->
                                    <option value="77">PUSH中</option>
                                </select>
                            </td>
                            <td>模板：</td>
                            <td>
                                <select name="templateId">
                                    <option value="">请选择</option>
                                </select>
                            </td>
                            <td>到期时间：</td>
                            <td>
                                <select name="expireTimeAsMonth">
                                    <option value="">请选择</option>
                                    <option value="3">3个月内</option>
                                    <option value="6">6个月内</option>
                                    <option value="12">12个月内</option>
                                    <option value="18">18个月内</option>
                                    <option value="24">24个月内</option>
                                </select>
                            </td>
                            <td></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td colspan="8" class="text_center">
                                <input type="submit" class="btn btn_primary" value="搜索">&nbsp;
                                <input type="reset" class="btn btn_default" value="重置">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <input type="hidden" name="sortField">
                <input type="hidden" name="sortMethod">
                <input type="hidden" name="pageSize" value="50">
            </form>
            <section class="mainResult">
                搜索结果<span class="text_orange">（<span id="domain_count">0</span>）</span>
            </section>
            <form action="/ym/list" id="domain_manage_form" method="post" target="_blank">
                <table class="table_style">
                    <thead>
                    <tr>
                        <th width="25%">
                            <input type="checkbox" id="select-all">
                            <label for="select-all">域名</label>
                        </th>
                        <th width="10%><span class=">注册时间<i class="def"></i></th>
                        <th width="10%><span class=">到期时间<i class="def"></i>
                        </th>
                        <th width="10%">注册商</th>
                        <th>分组</th>
                        <th width="18%">备注</th>
                        <th width="8%">状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody class="domain_list"><tr><td colspan="7" class="text_center">没有查询到相关的域名</td></tr></tbody>
                    <tfoot>
                    <tr>
                        <td colspan="2">
                            <input type="checkbox" class="select_all">
                            <select name="" id="batch_operation_select">
                                <option value="">请选择批量操作</option>
                                <!-- <option value="/domain/buy/publish/confirm">出售</option>-->
                                <!-- <option value="?ym_list/piliang">分组</option>
                                 <option value="?ym_list/xufei">续费</option>
                                 <option value="?ym_list/g_domainedit">模板过户</option>
                                 <option value="?ym_list/gaidns">修改DNS</option>
                                 <option value="?ym_list/ympush">域名PUSH</option>-->



                                <option value="分组">分组</option>
                                <option value="续费">续费</option>
                                <option value="解析">解析</option>
                                <option value="过户">模板过户</option>
                                <option value="修改DNS">修改DNS</option>
                                <option value="域名PUSH">域名PUSH</option>



                                <!--  <option value="/domain/show/add">添加展示页</option>
                                  <option value="TXT导出">TXT导出</option>-->
                                <option value="Excel导出">Excel导出</option>
                            </select>
                            <input class="btn btn_primary" id="batch_operation" type="button" value="批量操作">
                        </td>
                        <td colspan="5">
                            <div style="text-align: right">
                                每页&ensp;
                                <select name="pageSize" id="pageSize">
                                    <option value="50">50</option>
                                    <option value="100">100</option>
                                    <option value="200">200</option>
                                    <option value="300">300</option>
                                </select>&ensp;
                                条
                                <div class="pagination" style="display: inline-block;"><span class="disabled">&lt;</span><span class="disabled">&gt;</span></div>
                            </div>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </form>
        </div>
        <div class="warm_prompt">
            <div class="title">
                温馨提示
            </div>
            <ul>
                <li>1、非平台默认DNS的域名不能在本平台进行域名解析。</li>
                <li>2、注册局规定域名注册后不满60天的不能申请转出。</li>
            </ul>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function () {
            var link=  $("#domain-list");
            link.parent().parent().parent().addClass("active");
            link.parent().addClass("active");
        });

        function edittd(that) {
            $(that).parents('.change_tr').find('td').children('.bz').show();;
            var html = $(that).text();
            if ($('.replay-div').is(':visible')) {
                $('.replay-div').remove();
            }
            $(that).parents('td').append(' <div class="replay-div">\n' +
                '<input class="replay-inp" type="text" value=' + html + '></input>\n' +
                '<button class="replay-btn" type="button">确定</button>\n' +
                '</div>');
        }
        $(function () {
            /* loadingPage();*/
            $("select[name='groupId']").val('');
            $("select[name='status']").val("");

            //选后缀
            $('.suffix_container li').on('click', function (e) {
                e.stopPropagation();
                $(this).toggleClass("active");
                var selectedSize = $('.suffix_container li.active').length;
                var value = selectedSize ? "已选择" + selectedSize + "个后缀" : "所有后缀";
                $('.suffix_container [type="text"]').val(value);
            });

            var suffixCont = $('.suffix_container');
            var suffixList = $('.suffix_list');

            //显示后缀选框
            suffixCont.find('[type="text"]').on('click', function (e) {
                e.stopPropagation();
                var suffix = suffixCont.find('[type="hidden"]').val();
                var suffixLi = suffixList.find('li');
                suffixLi.removeClass('active');
                if (suffix) {
                    var arr = suffix.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        for (var j = 0; j < suffixLi.length; j++) {
                            if (suffixLi[j].innerHTML == arr[i]) {
                                suffixLi[j].className = 'active';
                            }
                        }
                    }
                }
                suffixList.fadeIn();
            });

            //确定后缀选择
            suffixCont.find('.btn_primary').on('click', function (e) {
                e.stopPropagation();
                var selected = $('.suffix_container li.active');
                var val = '';
                if (selected.length > 1) {
                    selected.each(function (i, v) {
                        if (i == 0) {
                            val += $(v).html();
                        } else {
                            val += ",";
                            val += $(v).html();
                        }
                    });
                } else {
                    val = selected.html();
                }
                suffixCont.find('[type="hidden"]').val(val);
                suffixList.fadeOut();
            });

            function cancelSuffixSel() {
                var suffix = suffixCont.find('[type="hidden"]').val();
                var val = suffix ? "已选择" + suffix.split(',').length + "个后缀" : "所有后缀";
                suffixCont.find('[type="text"]').val(val);
                suffixList.fadeOut();
            }

            suffixList.on('click', function (e) {
                e.stopPropagation();
            });
            $(document).on('click', cancelSuffixSel);

            //取消后缀选择
            suffixCont.find('.btn_default').on('click', cancelSuffixSel);

            $("a[data-type=normal]").trigger("click");

            function loadingPage() {
                var param = $("#queryForm").serializeJson();
                param.flag = 1;
                param.type1 = $("#type1").val();
                requestPage({
                    "url": "/ym/list",
                    "seoUrl": "",
                    "data": param,
                    "dataContainer": $(".domain_list"),
                    "pageContainer": $(".pagination"),
                    "notLoginMsg": "<tr><td colspan='7' class='text_center'>没有查询到相关的域名</td></tr>",
                    "notData": "<tr><td colspan='7' class='text_center'>没有查询到相关的域名</td></tr>"
                }, function (data) {
                    $("#domain_count").html(parseInt(data['totalRow'] || 0));
                });
            }

            loadingPage();

            $(".sub_nav_container li a").on("click", function () {
                $(this).parent('li').addClass('active').siblings('li').removeClass('active');
                $("#queryForm").find("input[name='type']").val($(this).data("type"));
                loadingPage();
            });

            $("#pageSize").on("change", function () {
                $("#queryForm").find("input[name='pageSize']").val($(this).val());
                loadingPage();
            });
            $("#queryForm").on("submit", function () {
                loadingPage();
                return false;
            });
            //  搜索，排序
            $("#queryBtn, .sort_style").on("click", function () {
                loadingPage();
            });

            //批量操作
            var $form = $("#domain_manage_form");
            $('#batch_operation').on('click', function (e) {
                e.preventDefault();
                var val = $('#batch_operation_select').val();
                if (val) {
                    if (val == '/domain/buy/publish/confirm') {
                        if ($form.find(":checkbox[name=id]:checked").length < 1) {
                            window.location.href = '/domain/buy/publish';
                        } else {
                            $form.attr("action", val).submit();
                        }
                    } else if (val == '分组') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&domin[]=" + $(this).data('ym');
                        });
                        window.location.href = "/ym/plfenzu&" + params;

                    }else if (val == '解析') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&ym[]=" + $(this).data('ym');
                        });
                        window.location.href = "/ym/pljx&" + params;

                    }else if (val == '续费') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&ym[]=" + $(this).data('ym');
                        });
                        window.location.href = "/ym/xufei&" + params;

                    }else if (val == '过户') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&ym[]=" + $(this).data('ym');
                        });
                        window.location.href = "/ym/guohu&" + params;

                    }else if (val == '修改DNS') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&ym[]=" + $(this).data('ym');
                        });
                        window.location.href = "/ym/dns&" + params;

                    }else if (val == '域名PUSH') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&ym[]=" + $(this).data('ym');
                        });
                        window.location.href = "/ym/push&" + params;

                    }else if (val == 'TXT导出' || val == 'Excel导出') {
                        var params = $('#queryForm').serialize();
                        $('.select_item:checked').each(function () {
                            params += "&id[]=" + $(this).val();
                        });
                        if (val == 'TXT导出') {
                            window.open("/domain/export?" + params);
                        } else {
                            window.open("/ym_list/print_list&" + params);
                        }
                    } else {
                        $form.attr("action", val).submit();
                    }
                }
            });

            /*$('.change_tr td').find('.bz').on('click', function () {

                console.log('zzzzzz');
                $(this).parents('.change_tr').find('td').children('.bz').show();
              //   $(this).hide();

                var html = $(this).text();
                if ($('.replay-div').is(':visible')) {
                    $('.replay-div').remove();
                }
                $(this).parents('td').append(' <div class="replay-div">\n' +
                    '<input class="replay-inp" type="text" value=' + html + '></input>\n' +
                    '<button class="replay-btn" type="button">确定</button>\n' +
                    '</div>');
            });*/
            $(document).on('click','.replay-btn',function(){

                var inpTxt = $.trim($(this).siblings('.replay-inp').val());
                // console.log(inpTxt);
                var that = this;
                var id = $(that).parents('td').attr('data-id');
                //console.log(id);
                $.ajax({
                    url:'/ym_list/edit_bz',
                    data:{
                        id:id,
                        bz:inpTxt
                    },
                    type:"post",
                    success:function(res){
                        if(res.code==1){
                            layer.msg(res.msg);
                            $(that).parents('td').find('.bz').empty().show().html(res.text);
                            $(that).parents('.replay-div').hide();
                            setTimeout(function(){
                                // loadingPage();
                                window.location.reload();
                            },2000);
                        }else{
                            layer.msg(res.msg);
                        }
                    }
                });
            });
        });
    </script>
    @endsection
